$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	debugger;
	var aa = $('#signupForm').serialize();
	$.ajax({
		cache : true,
		type : "POST",
		url : "/jiashan/saleOrder/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入姓名"
			}
		}
	})
}

function addOrderProduct(button){
	var butDiv = button.parentElement.parentElement;
	var contentDivCount = butDiv.parentElement.getElementsByClassName("form-group").length - 1;
	var i = contentDivCount;
	var newFromGroupDiv = document.createElement("div");
	newFromGroupDiv.classList.add("form-group");
	var divContent = '<label class="col-sm-2 control-label">货品：</label>\n' +
		'<div class="col-sm-3">\n' +
		'<input id="product" name="saleOrderInfoDOS['+i+'].productName" class="form-control" type="text" placeholder="输入货名">\n' +
		'</div>\n' +
		'<div class="col-sm-3">\n' +
		'<input id="norm" name="saleOrderInfoDOS['+i+'].productNorm" class="form-control" type="text" placeholder="输入规格">\n' +
		'</div>\n' +
		'<div class="col-sm-3">\n' +
		'<input id="count" name="saleOrderInfoDOS['+i+'].count" class="form-control" type="text" placeholder="输入数量">\n' +
		'</div>\n' +
		'<button type="button" class="col-sm-1 btn  btn-sm" onclick="removeOrderProduct(this)">\n' +
		'<i class="fa fa-remove"></i>\n' +
		'</button>';
	newFromGroupDiv.innerHTML = divContent;

	butDiv.parentElement.insertBefore(newFromGroupDiv, butDiv);
}

function removeOrderProduct(button){
	var fromGroupDiv = button.parentElement;
	fromGroupDiv.remove();
}